﻿Public Class FormPrincipal

    Public textoRecordatorio As Recordatorio
    Public _calendarioSemanal As ObjSemana
    Private baseDatos As BBDD
    Private _MyBaseDedatos As BBDDCita
    Private _move As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _move = 0
        _MyBaseDedatos = New BBDDCita
        textoRecordatorio = New Recordatorio()

        ToolStripStatusLabelHra.Text = Now
        TimerHora.Start()
        LabelReloj.Text = Now.ToString("HH:mm:ss")


        _calendarioSemanal = New ObjSemana(PanelCentralCalendarios, 5, ObjSemana._diasSemana.Viernes)
        _calendarioSemanal.CalcularFechas(Now)
        _calendarioSemanal.Ancho = PanelCentralCalendarios.Width - 70
        _calendarioSemanal.Alto = PanelCentralCalendarios.Height - 50
        _calendarioSemanal.X = 40
        _calendarioSemanal.Y = 25
        _calendarioSemanal.EstaBlecerRangoHoras("09:00", "20:00")

        _RecordatorioCuadro.Text = textoRecordatorio.texto

        labelFecha.Text = _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Lunes) & " - " & _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Viernes)
        cargarCitasHoy()
        PintarCalendarioSemanal()

    End Sub

    Public Sub cargarCitasHoy()
        baseDatos = New BBDD

        cbCitasHoy.Items.Clear()

        baseDatos.EjecutarComandoSelect("SELECT * FROM Citas, clientes where Citas.idCliente = clientes.IdCliente and Citas.fecha like #" & Now.ToString("dd/MM/yyyy") & "# order by horaEntrada asc")
        While baseDatos.lector.Read()
            Dim hora As Date = baseDatos.lector("horaEntrada")
            cbCitasHoy.Items.Add(baseDatos.lector("nombre") & " Hora " & hora.ToString("HH:mm"))
        End While
        baseDatos.lector.Close()
    End Sub

#Region "eventos form"

    Private Sub btGuardarRecordatorio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _RecordatorioCuadro.LostFocus
        textoRecordatorio.texto = _RecordatorioCuadro.Text
        textoRecordatorio.Guardar()
    End Sub

    Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub TimerHora_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerHora.Tick
        ToolStripStatusLabelHra.Text = Now
        LabelReloj.Text = Now.ToString("HH:mm:ss")
    End Sub

    Private Sub NuevoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuevoToolStripMenuItem.Click
        Dim Servicio As Servicios = New Servicios("0")
        Servicio.Show()
    End Sub

    Private Sub ModificarToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModificarToolStripMenuItem2.Click
        Dim Servicio As Servicios = New Servicios("1")
        Servicio.Show()
    End Sub

    Private Sub VisualizarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VisualizarToolStripMenuItem1.Click
        Dim Servicio As Servicios = New Servicios("2")
        Servicio.Show()
    End Sub

    Private Sub EliminarToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarToolStripMenuItem2.Click
        Dim Servicio As Servicios = New Servicios("3")
        Servicio.Show()
    End Sub

    Private Sub MonthCalendarMes_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendarMes.DateSelected

        Dim nuevoTiempo As Date
        nuevoTiempo = DateAdd(DateInterval.Day, -1, MonthCalendarMes.SelectionStart)
        _calendarioSemanal.CalcularFechas(nuevoTiempo.ToString("dd/MM/yyyy"))
        PintarCalendarioSemanal()
        labelFecha.Text = _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Lunes) & " - " & _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Viernes)
        _calendarioSemanal.Ancho = PanelCentralCalendarios.Width - 70
        _calendarioSemanal.Alto = PanelCentralCalendarios.Height - 50
        MonthCalendarMes.Visible = False
        PictureBoxMes.Enabled = True

    End Sub

    Private Sub MonthCalendarAnyo_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendarAnyo.DateSelected
        Dim nuevoTiempo As Date
        nuevoTiempo = DateAdd(DateInterval.Day, -1, MonthCalendarAnyo.SelectionStart)
        _calendarioSemanal.CalcularFechas(nuevoTiempo.ToString("dd/MM/yyyy"))
        PintarCalendarioSemanal()
        labelFecha.Text = _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Lunes) & " - " & _calendarioSemanal.RetornaFecha(ObjSemana._diasSemana.Viernes)
        _calendarioSemanal.Visible = True
        MonthCalendarAnyo.Visible = False
    End Sub

    Private Sub TimerAnimacion_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerAnimacion.Tick

        _move += 5

        _calendarioSemanal.Ancho = PanelCentralCalendarios.Width - (70 + _move)
        If _move > 220 Then

            TimerAnimacion.Stop()
            _move = 0
            MonthCalendarMes.Visible = True

            PictureBoxAnyo.Enabled = True
            PictureBoxMes.Enabled = False
            PictureBoxSemana.Enabled = True

        End If

    End Sub

    Private Sub InsertarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertarToolStripMenuItem.Click
        AgregarCliente.Show()

    End Sub

    Private Sub NuevvaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuevvaToolStripMenuItem.Click
        Form_Cita.Show()
    End Sub

#Region "eventos picture box"

    Private Sub Picture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxCita.Click, PictureBoxBuscar.Click, PictureBoxCliente.Click, PictureBoxCobrar.Click, _
        PictureBoxAnyo.Click, PictureBoxMes.Click, PictureBoxSemana.Click

        Dim auxPicture As PictureBox = CType(sender, PictureBox)

        Select Case auxPicture.Name
            Case PictureBoxCita.Name
                Form_Cita.Show()
            Case PictureBoxCliente.Name
                AgregarCliente.Show()
            Case PictureBoxCobrar.Name
                Cobrar.Show()
            Case PictureBoxBuscar.Name
                Busqueda.Show()
            Case PictureBoxSemana.Name
                'se recoloca el scroll del panel
                _calendarioSemanal.RecolocarPanel()
                _calendarioSemanal.Visible = True
                _calendarioSemanal.Ancho = PanelCentralCalendarios.Width - 70
                MonthCalendarMes.Visible = False
                MonthCalendarAnyo.Visible = False
                PictureBoxMes.Enabled = True
            Case PictureBoxMes.Name
                _calendarioSemanal.Visible = True
                TimerAnimacion.Start()
                MonthCalendarAnyo.Visible = False

                PictureBoxAnyo.Enabled = False
                PictureBoxMes.Enabled = False
                PictureBoxSemana.Enabled = False

            Case PictureBoxAnyo.Name
                _calendarioSemanal.Visible = False
                MonthCalendarMes.Visible = False
                MonthCalendarAnyo.Visible = True
                PictureBoxMes.Enabled = True
        End Select

    End Sub

    Private Sub Picture_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxCita.MouseHover, PictureBoxBuscar.MouseHover, PictureBoxCliente.MouseHover, PictureBoxCobrar.MouseHover, _
        PictureBoxAnyo.MouseHover, PictureBoxMes.MouseHover, PictureBoxSemana.MouseHover
        Dim auxPicture As PictureBox = CType(sender, PictureBox)

        Select Case auxPicture.Name
            Case PictureBoxCita.Name
                PictureBoxCita.BackgroundImage = Image.FromFile("Img/Botones/BDarCitaCon.png")
            Case (PictureBoxCliente.Name)
                PictureBoxCliente.BackgroundImage = Image.FromFile("Img/Botones/BClienteCon.png")
            Case PictureBoxCobrar.Name
                PictureBoxCobrar.BackgroundImage = Image.FromFile("Img/Botones/BCobrarCon.png")
            Case PictureBoxBuscar.Name
                PictureBoxBuscar.BackgroundImage = Image.FromFile("Img/Botones/BLupaCon.png")
            Case PictureBoxSemana.Name
                PictureBoxSemana.BackgroundImage = Image.FromFile("Img/Botones/BSemanaCon.png")
            Case PictureBoxMes.Name
                PictureBoxMes.BackgroundImage = Image.FromFile("Img/Botones/BMesCon.png")
            Case PictureBoxAnyo.Name
                PictureBoxAnyo.BackgroundImage = Image.FromFile("Img/Botones/BAñoCon.png")
        End Select

    End Sub

    Private Sub Picture_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxCita.MouseLeave, PictureBoxBuscar.MouseLeave, PictureBoxCliente.MouseLeave, PictureBoxCobrar.MouseLeave, _
        PictureBoxAnyo.MouseLeave, PictureBoxMes.MouseLeave, PictureBoxSemana.MouseLeave
        Dim auxPicture As PictureBox = CType(sender, PictureBox)

        Select Case auxPicture.Name
            Case PictureBoxCita.Name
                PictureBoxCita.BackgroundImage = Image.FromFile("Img/Botones/BDarCitaSin.png")
            Case (PictureBoxCliente.Name)
                PictureBoxCliente.BackgroundImage = Image.FromFile("Img/Botones/BClienteSin.png")
            Case PictureBoxCobrar.Name
                PictureBoxCobrar.BackgroundImage = Image.FromFile("Img/Botones/BCobrarSin.png")
            Case PictureBoxBuscar.Name
                PictureBoxBuscar.BackgroundImage = Image.FromFile("Img/Botones/BLupaSin.png")
            Case PictureBoxSemana.Name
                PictureBoxSemana.BackgroundImage = Image.FromFile("Img/Botones/BSemanaSin.png")
            Case PictureBoxMes.Name
                PictureBoxMes.BackgroundImage = Image.FromFile("Img/Botones/BMeSin.png")
            Case PictureBoxAnyo.Name
                PictureBoxAnyo.BackgroundImage = Image.FromFile("Img/Botones/BAñoSin.png")

        End Select

    End Sub

#End Region

#End Region

#Region "Metodos carga calendario Semana"

    Public Sub PintarCalendarioSemanal()

        _calendarioSemanal.Limpiar()
        Dim listaCita As List(Of Cita)
        'pintar el calendario por  la fecha y el dia 
        'diaSemana - 1 Lunes 2 martes etc.. Recorre hasta cinco pq es solo hasta el viernes
        For diaSemana = 1 To 5
            Dim fecha As String = _calendarioSemanal.RetornaFecha(diaSemana)
            listaCita = _MyBaseDedatos.BuscarCitaFecha(fecha)
            PintarCalendario(listaCita, diaSemana)
            listaCita.Clear()
        Next

    End Sub

    Private Sub PintarCalendario(ByVal listaDeCitas As List(Of Cita), ByVal DiaSemana As Integer)
        For indice = 0 To listaDeCitas.Count - 1
            _calendarioSemanal.DibujarCitasInformacion(DiaSemana, listaDeCitas(indice).horaInicio.ToString("HH:mm"), listaDeCitas(indice).Empleado.IdEmpleado, listaDeCitas(indice).ListaTratamiento(0).Tiempos, listaDeCitas(indice).idCita)
        Next
    End Sub

#End Region

   
End Class
